package com.chen.apipassenger.service;

import com.chen.apipassenger.remote.ServicePassengerUserClient;
import com.chen.internalcommon.dto.ResponseResult;
import com.chen.internalcommon.dto.TokenResult;
import com.chen.internalcommon.dto.UserInfo;
import com.chen.internalcommon.util.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author chenLiuPing
 **/
@Service
@Slf4j
public class UserService {
    @Autowired
    private ServicePassengerUserClient servicePassengerUserClient;

    public ResponseResult getUserByAccessToken(String accessToken) {
        log.info("getUserByAccessToken start");
        // 从accessToken中解析出phone
        TokenResult tokenResult = JwtUtils.parseToken(accessToken);
        String phone = tokenResult.getPhone();
        // 根据phone从数据库中查询用户信息
        ResponseResult<UserInfo> passengerUser = servicePassengerUserClient.getUser(phone);
//        UserInfo info = passengerUser.getData();
//        String passengerName = passengerUser.getData().getPassengerName();
//        String profilePhoto = passengerUser.getData().getProfilePhoto();
//        passengerUser.get
//        UserInfo userInfo = new UserInfo(passengerName, profilePhoto);
        return ResponseResult.success(passengerUser.getData());
    }
}
